//
//  ChangePasswordViewController.m
//  Business Club
//
//  Created by 尹宁 on 16/4/18.
//  Copyright © 2016年 范琦. All rights reserved.
//

#import "ChangePasswordViewController.h"
#import "UIViewController+HUD.h"
@interface ChangePasswordViewController ()
{
    NSString *token;
}
@end

@implementation ChangePasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor = [UIColor huiseColor];
    token = [NSUSERDEFAULTS objectForKey:@"gettoken"];
    self.title = @"修改密码";
}
- (IBAction)changePassword:(id)sender
{
    if (self.oldPassword.text.length ==0 || self.inputNewPassword.text.length == 0 || self.againNewPassword.text.length == 0)
    {
        [self showHint:@"请输入完整信息" yOffset:-300];
        return;
    } else if (![self.inputNewPassword.text isEqualToString:self.againNewPassword.text])
    {
        [self showHint:@"两次输入密码不一致" yOffset:-300];
        return;
    } else {
        
        NSDictionary *params = @{@"old_pass":self.oldPassword.text, @"new_pass":self.inputNewPassword.text};
        YTKNetHandle *api = [[YTKNetHandle alloc] initWithUrl:[NSString stringWithFormat:@"/User/chgPassword.html?token=%@", token] paramDic: params RegisterApiMethod:RequestMethodPost];
        [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
            NSString *error = [request.responseBody objectForKey:@"error"];
            if ([error isEqualToString:@"0"]) {
                [self showHint:@"修改密码成功" yOffset:-300];
                [self.navigationController popViewControllerAnimated:YES];
            } else {
                NSString *fault = [request.responseBody objectForKey:@"msg"];
                NSLog(@"%@", fault);
            }
        } failure:^(YTKBaseRequest *request) {
            
        }];
        return;
    }
    
}

- (void)getData
{
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
